home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cocktail / r2l.lha / r2l / m2c / DefTable.c next >
C/C++ Source or Header  |  1992-08-18  |  2KB  |  120 lines

  1. #include "SYSTEM_.h"
  2.  
  3. #ifndef DEFINITION_DynArray
  4. #include "DynArray.h"
  5. #endif
  6.  
  7. #ifndef DEFINITION_Idents
  8. #include "Idents.h"
  9. #endif
  10.  
  11. #ifndef DEFINITION_DefTable
  12. #include "DefTable.h"
  13. #endif
  14.  
  15. DefTable_DefRange DefTable_DefCount;
  16.  
  17. #define InitialDefTableSize    16
  18. typedef struct S_1 {
  19.     Idents_tIdent Symbol;
  20.     DefTable_tKind Kind;
  21. } DefType;
  22. typedef struct S_2 {
  23.     DefType A[100000 + 1];
  24. } DefTable;
  25. static DefTable *DefTablePtr;
  26. static LONGINT DefTableSize;
  27.  
  28.  
  29. void DefTable_MakeIdentDef
  30. # ifdef __STDC__
  31. (Idents_tIdent pSymbol)
  32. # else
  33. (pSymbol)
  34. Idents_tIdent pSymbol;
  35. # endif
  36. {
  37.   INC(DefTable_DefCount);
  38.   if (DefTable_DefCount == DefTableSize) {
  39.     DynArray_ExtendArray((ADDRESS *)&DefTablePtr, &DefTableSize, (LONGINT)sizeof(DefType));
  40.   }
  41.   {
  42.     register DefType *W_1 = &DefTablePtr->A[DefTable_DefCount];
  43.  
  44.     W_1->Symbol = pSymbol;
  45.     W_1->Kind = DefTable_Ident;
  46.   }
  47. }
  48.  
  49. void DefTable_MakeStartDef
  50. # ifdef __STDC__
  51. (Idents_tIdent pSymbol)
  52. # else
  53. (pSymbol)
  54. Idents_tIdent pSymbol;
  55. # endif
  56. {
  57.   INC(DefTable_DefCount);
  58.   if (DefTable_DefCount == DefTableSize) {
  59.     DynArray_ExtendArray((ADDRESS *)&DefTablePtr, &DefTableSize, (LONGINT)sizeof(DefType));
  60.   }
  61.   {
  62.     register DefType *W_2 = &DefTablePtr->A[DefTable_DefCount];
  63.  
  64.     W_2->Symbol = pSymbol;
  65.     W_2->Kind = DefTable_Start;
  66.   }
  67. }
  68.  
  69. DefTable_DefRange DefTable_GetDef
  70. # ifdef __STDC__
  71. (Idents_tIdent pSymbol)
  72. # else
  73. (pSymbol)
  74. Idents_tIdent pSymbol;
  75. # endif
  76. {
  77.   DefTable_DefRange Def;
  78.  
  79.   {
  80.     LONGINT B_1 = 1, B_2 = DefTable_DefCount;
  81.  
  82.     if (B_1 <= B_2)
  83.       for (Def = B_1;; Def += 1) {
  84.         if (DefTablePtr->A[Def].Symbol == pSymbol) {
  85.           return Def;
  86.         }
  87.         if (Def >= B_2) break;
  88.       }
  89.   }
  90.   return DefTable_NoDef;
  91. }
  92.  
  93. DefTable_tKind DefTable_GetKind
  94. # ifdef __STDC__
  95. (DefTable_DefRange pDef)
  96. # else
  97. (pDef)
  98. DefTable_DefRange pDef;
  99. # endif
  100. {
  101.   return DefTablePtr->A[pDef].Kind;
  102. }
  103.  
  104. void BEGIN_DefTable()
  105. {
  106.   static BOOLEAN has_been_called = FALSE;
  107.  
  108.   if (!has_been_called) {
  109.     has_been_called = TRUE;
  110.  
  111.     BEGIN_Idents();
  112.     BEGIN_DynArray();
  113.     BEGIN_Idents();
  114.  
  115.     DefTableSize = InitialDefTableSize;
  116.     DynArray_MakeArray((ADDRESS *)&DefTablePtr, &DefTableSize, (LONGINT)sizeof(DefType));
  117.     DefTable_DefCount = 0;
  118.   }
  119. }
  120.